#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import re
from urllib.request import urlopen
from multiprocessing.dummy import Pool
import chardet
def urllink(link):
    html_l = urlopen(link,timeout=120).read()
    encoding_dict = chardet.detect(html_l)
    web_encoding = encoding_dict['encoding']
    if web_encoding == 'utf-8' or web_encoding =='UTF-8':
        html = html_l
    else :
        html = html_l.decode('gbk','ignore').encode('utf-8')
    return html
    i=1
linkl="http://www.dazui88.com/tag/IMiss/20170826423652.html"%i
html=urllink(linkl)
plist = re.findall("<p>.*?</p>",html,re.S)
picurl = re.findall('img alt.*?src="(.*?)"',html2)
for n in picurl:
    p=1+p
    if not re.findall('http', n, re.s):
        n = 'http://www.dazui88.com' + n
    print(u'start xiazai ' + n)
    retu = request.get(n, stream=True)
    picpath = unicode(r'D:\pachong\IMiss\%s\%s' % (label, str(p) + '.jpg', 'utf-8'))
    file = open(picpath, 'wb')
    for chunk in retu.iter_content(chunk_size=1024*8):
        if chunk:
            file.write(chunk)
            file.flush()
    file.close()






















